package hongcaosp.app.android.modle.impl;

import android.text.TextUtils;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;

import java.io.File;
import java.util.List;

import hongcaosp.app.android.BuildConfig;
import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.bean.ContactListWrapper;
import hongcaosp.app.android.modle.bean.DirectoryWrapper;
import hongcaosp.app.android.modle.bean.DynamicVideo;
import hongcaosp.app.android.modle.bean.Pagebean;
import hongcaosp.app.android.modle.bean.User;
import hongcaosp.app.android.modle.bean.UserInfo;
import hongcaosp.app.android.modle.bean.UserInfoWrap;
import hongcaosp.app.android.modle.bean.Video;
import hongcaosp.app.android.modle.mi.UserModle;

public class UserModleImpl implements UserModle {
    @Override
    public void userInfo(int id,String token, DataCallBack<UserInfoWrap> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/userInfo").params(params).execute(dataCallBack);
    }

    @Override
    public void userWorks(int id, String token, int pageSize, int pageNum, DataCallBack<Pagebean<Video>> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("pageSize", pageSize);
        params.put("pageNumber", pageNum);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/userWorks").params(params).execute(dataCallBack);
    }

    @Override
    public void userDynamic(int id,String token, int pageSize, int pageNum, DataCallBack<Pagebean<DynamicVideo>> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("pageSize", pageSize);
        params.put("pageNumber", pageNum);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/userDynamic").params(params).execute(dataCallBack);
    }

    @Override
    public void userLoves(int id, String token, int pageSize, int pageNum, DataCallBack<Pagebean<Video>> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("pageSize", pageSize);
        params.put("pageNumber", pageNum);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/userLoves").params(params).execute(dataCallBack);
    }

    @Override
    public void followList(int id, String token, int pageSize, int pageNum, DataCallBack<Pagebean<User>> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("pageSize", pageSize);
        params.put("pageNumber", pageNum);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/followList").params(params).execute(dataCallBack);
    }

    @Override
    public void fansList(int id, String token, int pageSize, int pageNum, DataCallBack<Pagebean<User>> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("id", id);
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("pageSize", pageSize);
        params.put("pageNumber", pageNum);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/fansList").params(params).execute(dataCallBack);
    }

    @Override
    public void linkman(String token, DataCallBack<ContactListWrapper> dataCallBack) {
        HttpParams params = new HttpParams();
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/user/linkman").params(params).execute(dataCallBack);
    }

    @Override
    public void goodFriends(String token, DataCallBack<ContactListWrapper> dataCallBack) {
        HttpParams params = new HttpParams();
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/user/goodFriends").params(params).execute(dataCallBack);
    }

    @Override
    public void recommendUser(String token, int pageSize, int pageNum, DataCallBack<Pagebean<UserInfo>> dataCallBack) {
        HttpParams params = new HttpParams();
        if (!TextUtils.isEmpty(token)) {
            params.put("token", token);
        }
        params.put("pageSize", pageSize);
        params.put("pageNumber", pageNum);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/user/recommendUser").params(params).execute(dataCallBack);
    }

    @Override
    public void directoriesFriends(String token, List<String> mobile, DataCallBack<DirectoryWrapper> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("token", token);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < mobile.size(); i++) {
            if (i == mobile.size() - 1) {
                sb.append(mobile.get(i));
            } else {
                sb.append(mobile.get(i)).append(",");
            }

        }
        params.put("mobile", sb.toString());
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/user/directoriesFriends").params(params).execute(dataCallBack);
    }

    @Override
    public void editInfo(String token, String path, String nickName, String userCode, String userComment, String school,String schoolName, int sex,
                         String birthday, String locality, DataCallBack<BaseResponse> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("token", token);
        if (!TextUtils.isEmpty(path)) {
            params.put("path", path);
        }
        if (!TextUtils.isEmpty(nickName)) {
            params.put("nickname", nickName);
        }
        if (!TextUtils.isEmpty(userCode)) {
            params.put("userCode", userCode);
        }
        if (!TextUtils.isEmpty(userComment)) {
            params.put("userComment", userComment);
        }
        if (!TextUtils.isEmpty(school)){
            params.put("school", school);
        }
        if (!TextUtils.isEmpty(schoolName)){
            params.put("schoolName", schoolName);
        }
        if (sex > -1) {
            params.put("sex",sex);
        }
        if (!TextUtils.isEmpty(birthday)) {
            params.put("birthday",birthday);
        }
        if (!TextUtils.isEmpty(locality)) {
            params.put("locality",locality);
        }
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/user/editInfo").params(params).execute(dataCallBack);
    }

    @Override
    public void editUserHead(String token, File path, DataCallBack<UserInfoWrap> dataCallBack) {
        HttpParams params = new HttpParams();
        params.put("token", token);
        params.put("path", path);
        OkGo.<BaseResponse>post(BuildConfig.HOST + "/api/user/editUserHead").params(params).execute(dataCallBack);
    }
}
